from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-05-17 14:07:46.926340
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Mon, 17, May, 2021
Time: 14:07:51
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -48.2959
Nobs: 294.000 HQIC: -48.9719
Log likelihood: 3600.74 FPE: 3.43359e-22
AIC: -49.4235 Det(Omega_mle): 2.54104e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.358718 0.110095 3.258 0.001
L1.Burgenland 0.070775 0.058210 1.216 0.224
L1.Kärnten -0.225006 0.051834 -4.341 0.000
L1.Niederösterreich 0.109840 0.123247 0.891 0.373
L1.Oberösterreich 0.237603 0.120418 1.973 0.048
L1.Salzburg 0.283940 0.066198 4.289 0.000
L1.Steiermark 0.109295 0.084318 1.296 0.195
L1.Tirol 0.124649 0.058709 2.123 0.034
L1.Vorarlberg -0.034881 0.053863 -0.648 0.517
L1.Wien -0.028303 0.107297 -0.264 0.792
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.391238 0.126929 3.082 0.002
L1.Burgenland 0.005297 0.067110 0.079 0.937
L1.Kärnten 0.327033 0.059759 5.473 0.000
L1.Niederösterreich 0.114637 0.142091 0.807 0.420
L1.Oberösterreich -0.066521 0.138829 -0.479 0.632
L1.Salzburg 0.235069 0.076319 3.080 0.002
L1.Steiermark 0.097135 0.097210 0.999 0.318
L1.Tirol 0.132883 0.067685 1.963 0.050
L1.Vorarlberg 0.154746 0.062099 2.492 0.013
L1.Wien -0.383734 0.123702 -3.102 0.002
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.248818 0.056168 4.430 0.000
L1.Burgenland 0.107659 0.029697 3.625 0.000
L1.Kärnten -0.012079 0.026444 -0.457 0.648
L1.Niederösterreich 0.090046 0.062878 1.432 0.152
L1.Oberösterreich 0.283762 0.061434 4.619 0.000
L1.Salzburg 0.019000 0.033773 0.563 0.574
L1.Steiermark 0.002418 0.043017 0.056 0.955
L1.Tirol 0.068604 0.029952 2.290 0.022
L1.Vorarlberg 0.079259 0.027480 2.884 0.004
L1.Wien 0.114024 0.054740 2.083 0.037
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.194602 0.053899 3.610 0.000
L1.Burgenland 0.029378 0.028498 1.031 0.303
L1.Kärnten 0.008777 0.025376 0.346 0.729
L1.Niederösterreich 0.048807 0.060338 0.809 0.419
L1.Oberösterreich 0.393222 0.058953 6.670 0.000
L1.Salzburg 0.084468 0.032408 2.606 0.009
L1.Steiermark 0.135249 0.041279 3.276 0.001
L1.Tirol 0.050229 0.028742 1.748 0.081
L1.Vorarlberg 0.085504 0.026370 3.243 0.001
L1.Wien -0.031470 0.052529 -0.599 0.549
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.393751 0.105447 3.734 0.000
L1.Burgenland 0.104657 0.055752 1.877 0.060
L1.Kärnten 0.010805 0.049646 0.218 0.828
L1.Niederösterreich 0.043399 0.118043 0.368 0.713
L1.Oberösterreich 0.125731 0.115334 1.090 0.276
L1.Salzburg 0.064865 0.063403 1.023 0.306
L1.Steiermark 0.070233 0.080758 0.870 0.384
L1.Tirol 0.196853 0.056230 3.501 0.000
L1.Vorarlberg 0.041981 0.051589 0.814 0.416
L1.Wien -0.048967 0.102766 -0.476 0.634
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.186429 0.082796 2.252 0.024
L1.Burgenland -0.010108 0.043776 -0.231 0.817
L1.Kärnten -0.004795 0.038981 -0.123 0.902
L1.Niederösterreich -0.002808 0.092687 -0.030 0.976
L1.Oberösterreich 0.426213 0.090559 4.706 0.000
L1.Salzburg 0.015846 0.049784 0.318 0.750
L1.Steiermark -0.023982 0.063411 -0.378 0.705
L1.Tirol 0.154982 0.044151 3.510 0.000
L1.Vorarlberg 0.059954 0.040507 1.480 0.139
L1.Wien 0.203111 0.080692 2.517 0.012
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.197634 0.100440 1.968 0.049
L1.Burgenland 0.025813 0.053105 0.486 0.627
L1.Kärnten -0.072756 0.047288 -1.539 0.124
L1.Niederösterreich -0.028083 0.112438 -0.250 0.803
L1.Oberösterreich 0.008701 0.109857 0.079 0.937
L1.Salzburg 0.090650 0.060392 1.501 0.133
L1.Steiermark 0.312383 0.076923 4.061 0.000
L1.Tirol 0.457007 0.053560 8.533 0.000
L1.Vorarlberg 0.146770 0.049139 2.987 0.003
L1.Wien -0.135981 0.097886 -1.389 0.165
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.198499 0.119501 1.661 0.097
L1.Burgenland 0.042622 0.063183 0.675 0.500
L1.Kärnten -0.074548 0.056262 -1.325 0.185
L1.Niederösterreich 0.112277 0.133776 0.839 0.401
L1.Oberösterreich 0.011996 0.130705 0.092 0.927
L1.Salzburg 0.197431 0.071853 2.748 0.006
L1.Steiermark 0.134177 0.091522 1.466 0.143
L1.Tirol 0.051512 0.063724 0.808 0.419
L1.Vorarlberg 0.106758 0.058465 1.826 0.068
L1.Wien 0.226944 0.116463 1.949 0.051
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.467337 0.066953 6.980 0.000
L1.Burgenland -0.010066 0.035400 -0.284 0.776
L1.Kärnten -0.018010 0.031522 -0.571 0.568
L1.Niederösterreich 0.112147 0.074951 1.496 0.135
L1.Oberösterreich 0.313002 0.073230 4.274 0.000
L1.Salzburg 0.027559 0.040257 0.685 0.494
L1.Steiermark -0.042890 0.051277 -0.836 0.403
L1.Tirol 0.077121 0.035703 2.160 0.031
L1.Vorarlberg 0.104084 0.032756 3.178 0.001
L1.Wien -0.028794 0.065251 -0.441 0.659
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.161560 0.083297 0.164033 0.224554 0.076184 0.084737 0.000069 0.174210
Kärnten 0.161560 1.000000 0.053745 0.216167 0.190793 -0.062677 0.179989 0.023749 0.310831
Niederösterreich 0.083297 0.053745 1.000000 0.237185 0.098410 0.314451 0.141327 0.023913 0.311238
Oberösterreich 0.164033 0.216167 0.237185 1.000000 0.304173 0.256565 0.100883 0.061713 0.141843
Salzburg 0.224554 0.190793 0.098410 0.304173 1.000000 0.157344 0.071345 0.091740 0.039358
Steiermark 0.076184 -0.062677 0.314451 0.256565 0.157344 1.000000 0.097962 0.104250 -0.091261
Tirol 0.084737 0.179989 0.141327 0.100883 0.071345 0.097962 1.000000 0.156033 0.159649
Vorarlberg 0.000069 0.023749 0.023913 0.061713 0.091740 0.104250 0.156033 1.000000 -0.010370
Wien 0.174210 0.310831 0.311238 0.141843 0.039358 -0.091261 0.159649 -0.010370 1.000000